package fun.chutianshu.springsecurity_01.security;

import java.util.ArrayList;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
//实现了 spring security 中的用户信息服务类
//覆盖了接口中用来读取指定用户名用户信息的方法 loadUserByUsername
public class JwtUserDetailsService implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //写死用户名和密码
        //其中密码用  BCrypt 加密
        // 这里对应的明文是 password
        if ("xyz".equals(username)) {
            return new User("xyz", "$2a$10$slYQmyNdGzTn7ZLBXBChFOC9f6kFjAqPhccnP6DxlWXx2lPk1C3G6",
                    new ArrayList<>());
        } else {
            throw new UsernameNotFoundException("找不到用户： " + username);
        }
    }
}